//
//  MsgUserBusinessCardCell.swift
//  swiftim
//
//  Created by yangjian on 2023/6/13.
//

import Foundation


class MsgUserNameCardCell : MsgUserBaseCell {
    
    let cardHeadImageView = UIImageView()
    let cardNameLabel = UILabel()
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.configMsgSubViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func configMsgSubViews() {
        configBubbleView(superView: msgBackgroundView, aboveView: msgContentView)

        msgContentView.addSubview(cardHeadImageView)
        msgContentView.addSubview(cardNameLabel)

        stateLabel.snp.makeConstraints { make in
            make.bottom.equalTo(self.msgContentView.snp.bottom)
            make.right.equalTo(self.msgContentView.snp.left).offset(-20)
        }
        

        cardHeadImageView.snp.makeConstraints { make in
            make.top.equalTo(8)
            make.left.equalTo(8)
            make.width.equalTo(50)
            make.height.equalTo(50)
            make.right.equalTo(-MsgCellLayoutAdapterConfig.share.msgContentMaxWidth() - 8 - 50)
        }
        
        cardNameLabel.snp.makeConstraints { make in
            make.left.equalTo(cardHeadImageView.snp.right).offset(8)
            make.right.equalTo(-8)
            make.centerY.equalTo(cardHeadImageView)
        }
        
        let line = UIView()
        msgContentView.addSubview(line)
        let tagLabel = UILabel()
        msgContentView.addSubview(tagLabel)
        
        line.snp.makeConstraints { make in
            make.top.equalTo(cardHeadImageView.snp.bottom).offset(20)
            make.left.equalTo(8)
            make.right.equalTo(-8)
            make.height.equalTo(0.6)
        }
        
        tagLabel.snp.makeConstraints { make in
            make.top.equalTo(cardHeadImageView.snp.bottom).offset(22)
            make.bottom.equalTo(-2)
            make.left.equalTo(8)
            make.height.equalTo(16)
        }
        
        line.backgroundColor = UIColor.gray
        tagLabel.font = UIFont.systemFont(ofSize: 12)
        tagLabel.textColor = UIColor.gray
        tagLabel.text = "[个人名片]"
        
    }
    
    override func resetSubViewsLayout(showName: Bool, showHead: Bool) {
        super.resetSubViewsLayout(showName: showName, showHead: showHead)
        resetBubbleleView(aboveView: msgContentView)

    }
    
    override func bindFromModel(_ model: MsgCellBaseModel) {
        super.bindFromModel(model)
        
        let body = model.message.body as! EMCustomMessageBody
        let uid = body.customExt["uid"] ?? ""
        let nickname = body.customExt["nickname"] ?? "无"
        let avatar = body.customExt["avatar"]
        let show = NSMutableAttributedString()
        show.append(attributedString(string: nickname, font: UIFont.systemFont(ofSize: 16), color: UIColor.black))
        show.append(attributedString(string: "\n(\(uid))", font: UIFont.systemFont(ofSize: 13), color: UIColor.gray))
        cardNameLabel.attributedText = show.copy() as? NSAttributedString
        //需要加载网络图片
    }

    
    
    
    
}
